package com.redis.controller;

import com.redis.entity.TicketDTO;
import com.redis.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.regex.Pattern;

/**
 * @Author: Li
 * @Date: 2024/12/16 10:29
 * @Description:
 */

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;
    
    @GetMapping("login")
    public String login(String phone, String password) {
        if (!Pattern.compile("^(1[3-9]\\d{9})$").matcher(phone).matches()) {
            return "手机号格式错误";
        }
        return userService.login(phone, password);
    }
    
    @GetMapping("register")
    public String register(@RequestParam String phone, @RequestParam(required = false) String name, @RequestParam String password, @RequestParam String repassword) {
        if (!Pattern.compile("^(1[3-9]\\d{9})$").matcher(phone).matches()) {
            return "手机号格式错误";
        }
        return userService.register(phone, name, password, repassword);
    }
    
    @GetMapping("getAllTicket")
    public List<TicketDTO> getAllTicket(String uid) {
        return userService.getAllTicket(uid);
    }
}
